package main

import (
	"fmt"
	"sync"
	"time"

	"gitee.com/wu-jin-feng/kinfu/fgin"
	"github.com/gin-gonic/gin"
)

func main() {
	f := fgin.Fgin{}
	r := f.GetHttpServer("./test.yaml")
	redisClient1, _ := f.GetRedisClientByName("redisDB4")
	redisClient2, _ := f.GetRedisClientByName("redisDB5")

	r.GET("/haha", func(ctx *gin.Context) {
		redisClient1.Set(ctx, "haha1", "success", 100*time.Second)
		redisClient2.Set(ctx, "haha2", "success", 100*time.Second)
		fgin.ReturnJson(ctx, 200, "success", nil)
	})
	r.GET("/tryAct", func(ctx *gin.Context) {
		var wg sync.WaitGroup
		for i := 0; i < 100; i++ {
			wg.Add(1)
			go func(wg *sync.WaitGroup, i int) {
				redisClient1.Set(ctx, fmt.Sprintf("fginKey-%d", i), "kratoskrtatos", 300*time.Second)
				defer wg.Done()
			}(&wg, i)
		}
		wg.Wait()
		fgin.ReturnJson(ctx, 200, "success", nil)
	})
	f.Run(r)
}
